﻿Imports lbGlobalcom
Imports Oracle.DataAccess.Client
Public Class fConsultaVentas

    Private Sub btnConsulta_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConsulta.Click
        Try
            Using conn As OracleConnection = New OracleConnection(My.Settings.ConnectionString)
                Using cmd As OracleCommand = conn.CreateCommand
                    Dim Cons As cConsultas = New cConsultas(gbCampos)
                    If Cons.AddWhere("IDSEDE", txtIdSede.Text, "", "=") Then
                        cmd.Parameters.Add("PIDSEDE", OracleDbType.Varchar2).Value = txtIdSede.Text
                    End If
                    If Cons.AddWhere("IDDOCUMENTO", txtIdDocumento.Text, "", "=") Then
                        cmd.Parameters.Add("PIDDOCUMENTO", OracleDbType.Varchar2).Value = txtIdSede.Text
                    End If
                    If Cons.AddWhere("NUMERO", txtNumeroDoc.Text, "", "=") Then
                        cmd.Parameters.Add("PNUMERO", OracleDbType.Varchar2).Value = txtIdSede.Text
                    End If
                    If Cons.AddWhere("FECHADOCUMENTO", dtDesdeF.Value, dtHastaF.Value, "BETWEEN") Then
                        cmd.Parameters.Add("PFECHADOCUMENTODesde", OracleDbType.Date).Value = dtDesdeF.Value
                        cmd.Parameters.Add("PFECHADOCUMENTOHasta", OracleDbType.Date).Value = dtHastaF.Value
                    End If
                    If Cons.AddWhere("IDBODEGAORIGEN", txtBodegaOri.Text, "", "=") Then
                        cmd.Parameters.Add("PIDBODEGAORIGEN", OracleDbType.Varchar2).Value = txtBodegaOri.Text
                    End If
                    If Cons.AddWhere("IDTERCERO", txtIdCliente.Text, "", "=") Then
                        cmd.Parameters.Add("PIDTERCERO", OracleDbType.Varchar2).Value = txtIdCliente.Text
                    End If
                    If Cons.AddWhere("SUCURSAL", txtSucursal.Text, "", "=") Then
                        cmd.Parameters.Add("PSUCURSAL", OracleDbType.Int16).Value = txtSucursal.Text
                    End If
                    If Cons.AddWhere("IDMUNITERCERO", txtIdMunicipio.Text, "", "=") Then
                        cmd.Parameters.Add("PIDMUNITERCERO", OracleDbType.Varchar2).Value = txtIdMunicipio.Text
                    End If
                    If Cons.AddWhere("IDVENDEDOR", txtIdVendedor.Text, "", "=") Then
                        cmd.Parameters.Add("PIDVENDEDOR", OracleDbType.Varchar2).Value = txtIdVendedor.Text
                    End If
                    If Cons.AddWhere("IDPRODUCTO", txtDesdeProd.Text, txtHastaProd.Text, "BETWEEN") Then
                        cmd.Parameters.Add("PIDPRODUCTODesde", OracleDbType.Varchar2).Value = txtDesdeProd.Text
                        cmd.Parameters.Add("PIDPRODUCTOHasta", OracleDbType.Varchar2).Value = txtHastaProd.Text
                    End If
                    cmd.CommandText = Cons.qSelect + " FROM MOV_VENTASFACTURAS " + Cons.qWhere + Cons.qGroup
                    Dim dtVentas As New DataTable
                    Try
                        conn.Open()
                        dtVentas.Load(cmd.ExecuteReader)
                        conn.Close()
                        Cons.ConfigDataGrid(gvVentas, dtVentas, True, True)
                    Catch ex As Exception
                        MessageBox.Show(ex.Message)
                    End Try
                End Using
            End Using
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub
End Class